<?php

namespace Admin\Controller;


class CategoryController extends CommonController
{
    var $category;

    function __construct()
    {
        parent::__construct();
        $this->category = M('Category');
    }

    function index()
    {
        $categories = $this->category->select();
        $this->assign('categories', $categories);
        $this->display();
    }

    function add()
    {

        if (IS_POST) {

            $this->category->create();

            $categories = $this->category->add();
            $this->success('添加成功', U('index'));
        } else {
            $this->display();
        }
    }

    function edit()
    {
        $id = I('get.id');
        if (IS_POST) {
            $this->category->create();
            $this->category->where("id=$id")->save();
            $this->success('修改成功', U('index'));
        } else {
            $category = $this->category->find($id);
            $this->assign('category',$category);
            $this->display();
        }

    }

}